package com.smartthinking.CICPNL.home.objects;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

public class cls_getHTML {

	private DefaultHttpClient clientedenred;
	private HttpResponse response;
	private HttpGet postvalue;

	public String getHTML(String url) {

		 try{
 
			response = null;

			clientedenred = new DefaultHttpClient();
			postvalue = new HttpGet(url);

			String data;

			response = clientedenred.execute(postvalue);

			int status = 0;

			status = response.getStatusLine().getStatusCode();
			if (status != HttpStatus.SC_OK) {
				ByteArrayOutputStream ostream = new ByteArrayOutputStream();
				response.getEntity().writeTo(ostream);
				data = ostream.toString();
			} else {
				String result = "";
				BufferedReader reader = new BufferedReader(
						new InputStreamReader(response.getEntity().getContent()));

				String line = null;
				while ((line = reader.readLine()) != null) {
					result += line + "\n";
				}
				data = result;
				reader.close();
			}

				String res =	data.trim().substring(0,data.trim().length()-3);

			return res;
		 }catch (Exception ex)
		 {
			 return "01" ;
		 }
	 
	}
}
